import React, { useContext, useEffect } from "react";

import Style from "../styles/voterList.module.css"
import { VotingContext ,Voter} from "../context/Voter";
import VoterCard from "../components/VoterCard/VoterCard";



const voterList: React.FC = () => {
    const {
        getAllVoterData,
        voterArray,
    } = useContext(VotingContext)
    // 初始化加载数据
    useEffect(() => {
        getAllVoterData?.(); // 加可选链，避免 undefined 调用
    }, [])//依赖项：避免无限循环（如果 getAllVoterData 是稳定函数）

    return (
        <div className={Style.voterList}>
            <VoterCard voterArray={voterArray as Voter[]} />
        </div>
    )
}
export default voterList;